#!/usr/bin/env ruby

module RoadRunnerModule

class	Wrap

  def initialize(opt={})
    @SHELL=opt[:sh]
    @NUM=opt[:n]||10
    @log=opt[:log]
    @PIDS=[]
    @log.debug "Wrap initialize parameters => #{opt.inspect}"
  end


  def start!
    @log.info "DSMP perftest start!".center(60,'*')

    @NUM.times do|i|
    	@log.info "sh #{@SHELL} >> #{@SHLOG} 2>&1"
    	@PIDS << Process.fork do
    		@log.info `sh #{@SHELL} 2>&1`
    	end
    end

    @log.info "Waiting Processes => #{@PIDS.inspect}"
    Process.waitall
    @log.info "Processes down."
  end


  def end!
    @PIDS.each do |x|
    	@log.debug %x"kill -9 #{x}"
    end
  end

end


module Work
	def self.work(n,log,sh)
		svn=Wrap.new({:n=>n,:log=>log,:sh=>sh })
		svn.start!
	end
end


end